import React, { Component } from "react";

class Reftwo extends Component {
	// 获取数据
	getData = () => {
		console.log(this);
		let value = this.username.value;
		this.div.innerHTML = value;
	};
	render() {
		return (
			<>
				<h1>回调函数形式的[ref]:获取真实dom对象</h1>
				<input
					type="text"
					ref={(el) => {
						this.username = el;
					}}
				/>
				<button onClick={this.getData}>显示数据</button>
				<div
					ref={(el) => (this.div = el)}
					style={{
						width: "300px",
						height: "300px",
						border: "1px solid grey",
						wordBreak: "break-all",
					}}
				></div>
			</>
		);
	}
}

export default Reftwo;
